package job

import (
	"cloudops/src/common"
	"cloudops/src/config"
)

var (
	mockScriptContentNoArgs = `
kubectl get node 
`

	mockScriptContentWithArgs = `
kubectl get node $1
`

	mockScriptContentSleep = `
date 
echo hello
sleep 2
`

	mockScriptContentNoRoot = `
pwd
ls -l
echo hello
date > ./abc

`

	mockScriptContentPythonNoArgs = `#!/usr/bin/env python3
import time

print("哈哈.sleep1000")
time.sleep(1000)
`

	mockScriptContentPythonWithArgs = `#!/usr/bin/env python3
import sys


if __name__ == "__main__":
    args = sys.argv
    print("参数", args)
    print("加法结果", int(args[1]) + 10)

`
)

func MockTaskRun(sc *config.AgentConfig) {

	// t1 代表 没有参数的短任务
	t1 := &Task{
		Account:       "root",
		ScriptContent: mockScriptContentNoArgs,
		Id:            1,
		Sc:            sc,
	}
	// t1 代表 有参数的短任务
	t2 := &Task{
		Account:       "root",
		ScriptContent: mockScriptContentWithArgs,
		Args:          "k8s-master01",
		Id:            2,
		Sc:            sc,
	}

	// t1 代表 sleep
	t3 := &Task{
		Account:       "root",
		ScriptContent: mockScriptContentSleep,
		Id:            3,
		Sc:            sc,
	}

	// t4代表非root用户
	t4 := &Task{
		Account:       "root",
		ScriptContent: mockScriptContentNoRoot,
		Id:            4,
		Sc:            sc,
	}

	// t4代表 root python 长时间
	t5 := &Task{
		Account:       "daihao",
		ScriptContent: mockScriptContentPythonNoArgs,
		ScriptType:    common.AGENT_TASK_SCRIPT_TYPE_PYTHON,
		Id:            5,
		Sc:            sc,
	}

	t6 := &Task{
		Account:       "daihao",
		ScriptContent: mockScriptContentPythonWithArgs,
		ScriptType:    common.AGENT_TASK_SCRIPT_TYPE_PYTHON,
		Id:            6,
		Sc:            sc,
		Args:          "100",
	}

	t7 := &Task{
		Account:       "daihao",
		ScriptContent: mockScriptContentPythonWithArgs,
		ScriptType:    common.AGENT_TASK_SCRIPT_TYPE_PYTHON,
		Id:            7,
		Sc:            sc,
		Args:          "100",
	}
	ts := []*Task{
		t1,
		t2,
		t3,
		t4,
		t5,
		t6,
		t7,
	}
	for _, t := range ts {
		t := t
		t.SetTaskDir()
		t.Start()
	}
}
